#include "Common.h"
#include "RenderQueue.h"
#include "Renderable.h"
#include "RenderQueueGroup.h"

RenderQueue::RenderQueue(void)
{
	for (int i = 0; i < ERQG_Max; i++)
		mRenderQueueGroup[i] = NULL;
}

RenderQueue::~RenderQueue(void)
{
	for (int i = 0; i < ERQG_Max; i++)
	{
		if (mRenderQueueGroup[i] != NULL)
			delete mRenderQueueGroup[i];
		mRenderQueueGroup[i] = NULL;
	}
}

void RenderQueue::Clear()
{
	for (int i = 0; i < ERQG_Max; i++)
	{
		if (mRenderQueueGroup[i] != NULL)
			mRenderQueueGroup[i]->Clear();
	}
}

void RenderQueue::AddRenderable(Renderable* renderable)
{
	int group = renderable->getRenderGroup();
	assert(group >=0 && group < ERQG_Max);

	if (mRenderQueueGroup[group] == NULL)
		mRenderQueueGroup[group] = new RenderQueueGroup();

	mRenderQueueGroup[group]->AddRenderable(renderable);
}